<?php

namespace app\controllers;

use app\models\System;
use app\models\system\SetApp;

use app\redis\Cache;

/**
 * Class SystemController
 * @package app\controllers
 */
class SystemController extends Controller
{
    /**
     * show test version
     *
     * @return \yii\web\Response
     */
    public function actionShowTest()
    {
        $data = Cache::get(Cache::$SYS_SHOW_TEST);
        if ($data === null) {
            $set = SetApp::getLastOne();
            $data = $set->open_test;
            Cache::set(Cache::$SYS_SHOW_TEST, $data);
        }

        return $this->success(boolval($data));
    }

    /**
     * system info
     *
     * @return \yii\web\Response
     */
    public function actionSystemInfo()
    {
        $data = Cache::get(Cache::$SYS_INFO);
        if ($data === null) {
            $system = System::getLastOne();
            $set = SetApp::getLastOne();
            $data = [
                'info' => [
                    'version' => $system->version,
                    'keywords' => $system->keywords,
                    'copyright' => $system->copyright,
                    'createTime' => $system->create_time,
                    'contact' => $system->contact,
                ],
                'show' => $set->show_system
            ];
            Cache::set(Cache::$SYS_INFO, json_encode($data));
        } else {
            $data = json_decode($data, true);
        }

        return $this->success([
            'info' => $data['info'],
            'show' => boolval($data['show'])
        ], 'by Cyzz @ 2021.08');
    }

    // 是否只能线下支付
    public function actionOfflinePay()
    {
        $set = SetApp::getLastOne();
        $set = $set->only_offline_pay == 1;

        return $this->success(['pay' => $set]);
    }
}